package com.example.jiangzhu.mvpdemo.demo;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.example.jiangzhu.mvpdemo.R;
import com.example.jiangzhu.mvpdemo.model.ILoginListener;
import com.example.jiangzhu.mvpdemo.presenter.IUserPresenter;
import com.example.jiangzhu.mvpdemo.view.IUserView;

public class MainActivity extends AppCompatActivity implements IUserView{


   /* public static Toast toast;
    public static void getToast(Context context,String countent){
        if (toast==null){
            toast = Toast.makeText(context,countent,Toast.LENGTH_SHORT);
        }else {
            toast.setText(countent);
        }
        toast.show();
    }*/
    private EditText name, pass;
    private Context context;
    private IUserPresenter iUserPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context = this;
        this.setTitle("胡泽");
        name = (EditText) findViewById(R.id.name);
        pass = (EditText) findViewById(R.id.pass);
        iUserPresenter = new IUserPresenter(this);
    }

    public void log(View view){
        iUserPresenter.login(loginListener);
    }

    @Override
    public String getUserName() {
        return name.getText().toString().trim();
    }

    @Override
    public String getUserPsd() {
        return pass.getText().toString().trim();
    }


    private ILoginListener loginListener = new ILoginListener() {
        @Override
        public void onSucess() {
            Toast.makeText(context, "成功", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onFail() {
            Toast.makeText(context, "失败", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onError() {
            Toast.makeText(context, "数据不完整", Toast.LENGTH_SHORT).show();
        }
    };

}
